//
//  CollectionTableViewCell.m
//  BGM
//
//  Created by liuqin on 2018/11/26.
//  Copyright © 2018年 com.alirtc.demo. All rights reserved.
//

#import "CollectionTableViewCell.h"
#import "Common.h"
#import "CommonBtn.h"
#import "UIImageView+WebCache.h"

@interface CollectionTableViewCell()

//头像
@property (nonatomic, strong)UIImageView *headImage;
//姓名
@property (nonatomic, strong)UILabel *nameLabel;
//内容
@property (nonatomic, strong)UILabel *messageLabel;
//状态
@property (nonatomic, strong)UIImageView *statusImage;
//状态结果
@property (nonatomic, strong)UILabel *resultLabel;
//评论
@property (nonatomic, strong)CommonBtn *commentBtn;
//转发
@property (nonatomic, strong)CommonBtn *forwardBtn;
//帮转红包/有偿
@property (nonatomic, strong)UILabel *label1; //帮转红包
@property (nonatomic, strong)UILabel *label2; //有偿


@end

@implementation CollectionTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self != nil) {
        
        self.backgroundColor = [UIColor clearColor];
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(15, 10, SCREENW-30, 100)];
        bgView.backgroundColor = [UIColor whiteColor];
        bgView.layer.cornerRadius = 6;
        bgView.layer.masksToBounds = YES;
        [self addSubview:bgView];
        
        
        //头像
        self.headImage = [[UIImageView alloc]initWithFrame:CGRectMake(15, 25, bgView.frame.size.height/2, bgView.frame.size.height/2)];
        self.headImage.layer.masksToBounds = YES;
        self.headImage.layer.cornerRadius = self.headImage.frame.size.height/2;
        self.headImage.contentMode = UIViewContentModeScaleAspectFill;
        [bgView addSubview:self.headImage];
        
        self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.headImage.frame.origin.x+self.headImage.frame.size.width+10, 10, bgView.frame.size.width-self.headImage.frame.size.width-30, bgView.frame.size.height/4)];
         self.nameLabel.textColor = bgmgrayColor;
        self.nameLabel.font = [UIFont systemFontOfSize:15];
        [bgView addSubview:self.nameLabel];
        
        self.statusImage = [[UIImageView alloc]initWithFrame:CGRectMake(self.nameLabel.frame.origin.x, self.nameLabel.frame.origin.y+self.nameLabel.frame.size.height+5, 20, 20)];
         [bgView addSubview:self.statusImage];

        
        
        self.messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.statusImage.frame.origin.x+self.statusImage.frame.size.width+5, self.statusImage.frame.origin.y-3, bgView.frame.size.width-self.headImage.frame.size.width-30-self.headImage.frame.size.width, bgView.frame.size.height/4)];
        self.messageLabel.textColor = bgmmainColor;
        self.messageLabel.font = [UIFont systemFontOfSize:17];
        [bgView addSubview:self.messageLabel];
        
        self.commentBtn = [[CommonBtn alloc]initWithFrame:CGRectMake(bgView.frame.size.width-100, bgView.frame.size.height-30, 50, 30)];
        [self.commentBtn setImage:[UIImage imageNamed:@"pinglun"] forState:UIControlStateNormal];
        [bgView addSubview:self.commentBtn];
        
        self.forwardBtn = [[CommonBtn alloc]initWithFrame:CGRectMake(bgView.frame.size.width-50, bgView.frame.size.height-30, 50, 30)];
        [self.forwardBtn setImage:[UIImage imageNamed:@"zhuanfa"] forState:UIControlStateNormal];
        [self.forwardBtn setTitle:@"52" forState:UIControlStateNormal];
        [bgView addSubview:self.forwardBtn];
        
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(bgView.frame.size.width-80, self.nameLabel.frame.origin.y+5, 10, 10)];
        label.backgroundColor = bgmColor(252, 225, 83);
        label.layer.cornerRadius = 5;
        label.layer.masksToBounds = YES;
        [bgView addSubview:label];
        
        self.resultLabel = [[UILabel alloc]initWithFrame:CGRectMake(label.frame.size.width+label.frame.origin.x+10, label.frame.origin.y, 60, 10)];
        self.resultLabel.text = @"进行中";
        self.resultLabel.textColor = bgmgrayColor;
        self.resultLabel.font = [UIFont systemFontOfSize:13];
        [bgView addSubview:self.resultLabel];
        
        
        
        
        
        self.label1 = [[UILabel alloc]initWithFrame:CGRectMake(self.nameLabel.frame.origin.x, self.commentBtn.frame.origin.y, 50, 20)];
        self.label1.text = @"有偿";
        self.label1.textColor = bgmgrayColor;
        self.label1.backgroundColor = bgmColor(250, 241, 194);
        self.label1.font = [UIFont systemFontOfSize:12];
        self.label1.layer.cornerRadius = 9;
        self.label1.layer.masksToBounds = YES;
        self.label1.textAlignment = NSTextAlignmentCenter;
        self.label1.layer.borderColor = bgmColor(250, 203, 11).CGColor;
        self.label1.layer.borderWidth = 1;
        [bgView addSubview:self.label1];
        
        self.label2 = [[UILabel alloc]initWithFrame:CGRectMake(self.label1.frame.origin.x+self.label1.frame.size.width+5, self.commentBtn.frame.origin.y, 70, 20)];
        self.label2.text = @"帮转红包";
        self.label2.textColor = bgmgrayColor;
        self.label2.backgroundColor = bgmColor(250, 241, 194);
        self.label2.font = [UIFont systemFontOfSize:12];
        self.label2.layer.cornerRadius = 9;
        self.label2.layer.masksToBounds = YES;
        self.label2.textAlignment = NSTextAlignmentCenter;
        self.label2.layer.borderColor = bgmColor(250, 203, 11).CGColor;
        self.label2.layer.borderWidth = 1;
        [bgView addSubview:self.label2];
        
        self.upView = [[UIView alloc]initWithFrame:bgView.bounds];
        self.upView.backgroundColor = [UIColor grayColor];
        self.upView.alpha = 0.3;
        [bgView addSubview:self.upView];
        
        self.deleBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
        [self.deleBtn setImage:[UIImage imageNamed:@"deleCollection"] forState:UIControlStateNormal];
        self.deleBtn.center = bgView.center;
        
        [self.deleBtn addTarget:self action:@selector(clickDele:) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:self.deleBtn];
        self.upView.hidden = YES;
        self.deleBtn.hidden = YES;
        
        
        
        
    }
    return self;
}
-(void)clickDele:(UIButton *)btn{
    int tag = (int)btn.tag;
    [self.collectionDelegate deleCollection:tag];
}
-(void)cellWithMessage:(NSDictionary *)dic{
    self.deleBtn.hidden = YES;
    self.upView.hidden = YES;
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[dic objectForKey:@"userHead"]]] placeholderImage:[UIImage imageNamed:@"headImage"]];
    self.nameLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"userName"]];
    [self.statusImage setImage:[UIImage imageNamed:[NSString stringWithFormat:@"push_%@",[dic objectForKey:@"publishTypeId"]]]];
    self.messageLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"publishTitle"]];
    [self.commentBtn setTitle:[NSString stringWithFormat:@"%@",[dic objectForKey:@"publishCommentsSize"]] forState:UIControlStateNormal];
    [self.forwardBtn setTitle:[NSString stringWithFormat:@"%@",[dic objectForKey:@"publishHelpSize"]] forState:UIControlStateNormal];
    
    NSString *str = [NSString stringWithFormat:@"%@",[dic objectForKey:@"publishType"]];
    if ([str isEqualToString:@"1"]) {
        self.resultLabel.text = @"进行中";

    }else if ([str isEqualToString:@"2"]){
        self.resultLabel.text = @"已结束";
    }
    
    str = [NSString stringWithFormat:@"%@",[dic objectForKey:@"publishItisPaid"]];
    if ([str isEqualToString:@"1"]) {
        self.label1.text = @"有偿";
    }else{
        self.label1.text = @"无偿";
    }
    str = [NSString stringWithFormat:@"%@",[dic objectForKey:@"publishRedPacakge"]];
    if ([str isEqualToString:@"0"]) {
        self.label2.hidden = YES;
    }else{
        self.label2.hidden = NO;
    }

}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
